<?php  
	class Cart
	{
		private $itemids;
		private $itemAmounts;
		private $currentIndex = 0;
		
		public function __construct()
		{
			$itemids[0] = -1;
			$currentIndex = 0;
			$itemAmounts = -1;
		}			
		
		public function addItemToCart($itemId)
		{	
			if($this->currentIndex == 0)
			{		
				$this->itemids[$this->currentIndex] = $itemId;
				$this->itemAmounts[$this->currentIndex] = 1;
				$this->currentIndex = $this->currentIndex + 1;
			}
			else 
			{
				for($i = 0; $i < $this->currentIndex; $i++)
				{
					if($this->itemids[$i] == $itemId)
					{
						$this->itemAmounts[$i] = $this->itemAmounts[$i] + 1;
						return;
					}
				}
				$this->itemids[$this->currentIndex] = $itemId;
				$this->itemAmounts[$this->currentIndex] = 1;
				$this->currentIndex = $this->currentIndex + 1;
			}
		}
		
		public function removeItemFromCart($itemId)
		{

			for($i=0; $i < $this->currentIndex; $i++)
			{
				if($this->itemids[$i] == $itemId)
				{
					if($this->itemAmounts[$i] > 1)
					{
						$this->itemAmounts[$i] = $this->itemAmounts[$i] - 1;
						return;
					}
					else 
					{
						for($j = $i; $j < $this->currentIndex - 1; $j++)
						{
							$this->itemids[$j] = $this->itemids[$j+1];
							$this->itemAmounts[$j] = $this->itemAmounts[$j+1];
						}
						$this->currentIndex = $this->currentIndex - 1;
						break;
					}
				}
			}
			
		}
		
		public function returnCart()
		{
			return $this->itemids;
		}
		
		public function returnIndex()
		{
			return $this->currentIndex;
		}
		public function returnCartAmounts()
		{
			return $this->itemAmounts;
		}
		
	}

?>